﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VPC.BL;
using VPC.BO;

namespace VPC.UI
{
    public partial class Registercs : Form
    {
        public Registercs()
        {
            InitializeComponent();
        }

        private void buttonRegister_Click(object sender, EventArgs e)
        {
            string sLogin = textfieldLogin.Text;
            string sPassword = textfieldPassword.Text;
            string sPasswordRe = textfieldPasswordRe.Text;

            try
            {
                if (sLogin == "")
                {
                    MessageBox.Show("Please enter a login !");
                }
                else
                {
                    if (sPassword == sPasswordRe && sPassword != "")
                    {
                        UserBO objUserBO = new UserBO();

                        objUserBO.Username = sLogin;
                        objUserBO.Password = sPassword;

                        if (UserBL.RegisterNewUser(objUserBO) == 1)
                        {
                            MessageBox.Show("You are register. Thank you");
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("An error occured during registration process. Please try again.");
                            this.Hide();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Passwords do not match. Please type again !");
                        textfieldPassword.Text = "";
                        textfieldPasswordRe.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}
